package others.swing.p006;

import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTable;

/**
 * 宿舍管理系统
 * 详细介绍： https://blog.csdn.net/WeiHao0240/article/details/120884095
 */
public class Window extends JFrame implements ActionListener {
    private static final long serialVersionUID = 1L;
    MenuBar menubar;
    Menu menu1, menu2, menu3, menu4, menu5, menu6;
    MenuItem a1, s1, i2, a2, d2, s2, a3, s3, i4, a4, d4, s4;
    JLabel t;
    JTable table;

    Window() {
        super("宿舍信息管理系统");
        setBounds(200, 200, 520, 230);
        setLayout(null);

        t = new JLabel();
        t.setText("欢迎登陆宿舍信息管理系统");
        t.setBounds(104, 100, 312, 50);
        t.setFont(new Font("Dialog", 1, 25));
        t.setForeground(new Color(255, 144, 85));
        add(t);

        menubar = new MenuBar();
        setMenuBar(menubar);
        menu1 = new Menu("宿舍楼基本信息");
        menu1.setFont(new Font("Dialog", 1, 15));
        menu2 = new Menu("楼栋管理员信息");
        menu2.setFont(new Font("Dialog", 1, 15));
        menu3 = new Menu("  宿舍居住信息 ");
        menu3.setFont(new Font("Dialog", 1, 15));
        menu4 = new Menu("  学生基本信息 ");
        menu4.setFont(new Font("Dialog", 1, 15));

        menubar.add(menu1);
        menubar.add(menu2);
        menubar.add(menu3);
        menubar.add(menu4);

        a1 = new MenuItem("ALL");
        a1.addActionListener(this);
        a1.setFont(new Font("Dialog", 1, 12));
        s1 = new MenuItem("查询");
        s1.addActionListener(this);
        s1.setFont(new Font("Dialog", 1, 12));

        i2 = new MenuItem("增加");
        i2.addActionListener(this);
        i2.setFont(new Font("Dialog", 1, 12));
        a2 = new MenuItem("ALL");
        a2.addActionListener(this);
        a2.setFont(new Font("Dialog", 1, 12));
        d2 = new MenuItem("删除");
        d2.addActionListener(this);
        d2.setFont(new Font("Dialog", 1, 12));
        s2 = new MenuItem("查询");
        s2.addActionListener(this);
        s2.setFont(new Font("Dialog", 1, 12));

        a3 = new MenuItem("ALL");
        a3.addActionListener(this);
        a3.setFont(new Font("Dialog", 1, 12));
        s3 = new MenuItem("查询");
        s3.addActionListener(this);
        s3.setFont(new Font("Dialog", 1, 12));

        i4 = new MenuItem("增加");
        i4.addActionListener(this);
        i4.setFont(new Font("Dialog", 1, 12));
        a4 = new MenuItem("ALL");
        a4.addActionListener(this);
        a4.setFont(new Font("Dialog", 1, 12));
        d4 = new MenuItem("删除");
        d4.addActionListener(this);
        d4.setFont(new Font("Dialog", 1, 12));
        s4 = new MenuItem("查询");
        s4.addActionListener(this);
        s4.setFont(new Font("Dialog", 1, 12));

        menu1.add(a1);
        menu1.add(s1);

        menu2.add(i2);
        menu2.add(a2);
        menu2.add(d2);
        menu2.add(s2);

        menu3.add(a3);
        menu3.add(s3);

        menu4.add(i4);
        menu4.add(a4);
        menu4.add(d4);
        menu4.add(s4);

        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        setVisible(true);
        validate();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == a1) {
            new table_all_d();
        }
        if (e.getSource() == s1) {
            Frame f = new Frame();
            SelectDorm a = new SelectDorm(f);
            a.setVisible(true);
        }
        if (e.getSource() == i2) {
            Frame f = new Frame();
            InsertAdmin a = new InsertAdmin(f);
            a.setVisible(true);
        }
        if (e.getSource() == a2) {
            new table_all_w();
        }
        if (e.getSource() == d2) {
            Frame f = new Frame();
            DeleteAdmin a = new DeleteAdmin(f);
            a.setVisible(true);
        }
        if (e.getSource() == s2) {
            Frame f = new Frame();
            SelectAdmin a = new SelectAdmin(f);
            a.setVisible(true);
        }
        if (e.getSource() == a3) {
            new table_all_r();
        }
        if (e.getSource() == s3) {
            Frame f = new Frame();
            SelectRoom a = new SelectRoom(f);
            a.setVisible(true);
        }
        if (e.getSource() == i4) {
            Frame f = new Frame();
            InsertStu a = new InsertStu(f);
            a.setVisible(true);
        }
        if (e.getSource() == a4) {
            new table_all_s();
        }
        if (e.getSource() == d4) {
            Frame f = new Frame();
            DeleteStu a = new DeleteStu(f);
            a.setVisible(true);
        }
        if (e.getSource() == s4) {
            Frame f = new Frame();
            SelectStu a = new SelectStu(f);
            a.setVisible(true);
        }
    }

    public static void main(String args[]) {
        new Window();
        DBconnect db = new DBconnect();
        try {
            db.closeDB();
        } catch (SQLException e1) {
            e1.printStackTrace();
        }
    }
}
